﻿ using nplJobsCommon.JobSeeker;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace nplJobsDAL.Insert
{
    public class InsertJobSeekerProfessionalInfo : DataAccessBase
    {
    
        public Int64 lastJobSeekerProfessionalInfoID;
        public string CheckUnique;
        
        public ProfessionalInfo ProfessionalInfo { get; set; }

        public InsertJobSeekerProfessionalInfo()
        {
            StoredProcedureName = StoredProcedure.Name.spInsertJobSeekerProfessionalInfo.ToString();
        }

        public void Insert()
        {
            InsertProfessionalInfoInfoDataParameters educationInfoInsertDataParameters = new InsertProfessionalInfoInfoDataParameters(this.ProfessionalInfo);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = educationInfoInsertDataParameters.Parameters;
            object LastJobSeekerProfessionalInfoID = dbHelper.RunScalar();

            if (LastJobSeekerProfessionalInfoID != null)
            {
                lastJobSeekerProfessionalInfoID = (Int64)LastJobSeekerProfessionalInfoID;
            }
            else
            {
                lastJobSeekerProfessionalInfoID = -1;
            }
        }
    }

    #region SQL parameters for professional info data parameters
    public class InsertProfessionalInfoInfoDataParameters
    {      
        public int CkeckUnique;
        private SqlParameter[] _parameters;
        public int lastJobSeekerProfessionalInfoID;

        public InsertProfessionalInfoInfoDataParameters(ProfessionalInfo professionalInfo)
        {
            this.ProfessionalInfo = professionalInfo;
            Build();
        }
        
        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    new SqlParameter("@CompanyName", ProfessionalInfo.CompanyName),
                    new SqlParameter("@IndustryID", ProfessionalInfo.IndustryID),
                    new SqlParameter("@Title", ProfessionalInfo.Title),
                    new SqlParameter("@JobTypeID", ProfessionalInfo.JobTypeID),
                    new SqlParameter("@CareerLevelID", ProfessionalInfo.CareerLevelID),
                    new SqlParameter("@EmployeeRangeID", ProfessionalInfo.EmployeeRangeID),
                    new SqlParameter("@OrganizationTypeID", ProfessionalInfo.OrganizationTypeID),
                    new SqlParameter("@CompanyHomePage", ProfessionalInfo.CompanyHomePage),
                    new SqlParameter("@CurrentPosition", ProfessionalInfo.CurrentPosition),
                    new SqlParameter("@PositionDescription", ProfessionalInfo.PositionDescription),
                    new SqlParameter("@DisplayAtTop", ProfessionalInfo.DisplayAtTop),
                    new SqlParameter("@FromDate", ProfessionalInfo.FromDate),
                    new SqlParameter("@ToDate", ProfessionalInfo.ToDate),
                    new SqlParameter("@IsDeleted", ProfessionalInfo.IsDeleted),
                    new SqlParameter("@JobSeekerID", ProfessionalInfo.JobSeekerID),
                    new SqlParameter("@Address", ProfessionalInfo.Address),
                    new SqlParameter("@ProfessionalInfoID", ProfessionalInfo.ProfessionalInfoID),
                    new SqlParameter("@PInfoID", lastJobSeekerProfessionalInfoID){ Direction= System.Data.ParameterDirection.ReturnValue},

                };

            Parameters = parameters;
        }

        public ProfessionalInfo ProfessionalInfo { get; set; }

        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }
    }
    #endregion
}

